import methyDataUpShowLabel from '/src/static/analysisData/methylation_wald_Up_showLabel.json';
import methyDataUpNoLabel from '/src/static/analysisData/methylation_wald_Up_noLabel.json';
import methyDataNoShowLabel from '/src/static/analysisData/methylation_wald_No_showLabel.json';
import methyDataNoNoLabel from '/src/static/analysisData/methylation_wald_No_noLabel.json';
import methyDataDownShowLabel from '/src/static/analysisData/methylation_wald_Down_showLabel.json';
import methyDataDownNoLabel from '/src/static/analysisData/methylation_wald_Down_noLabel.json';
import { createScatterSeries, formatDecimal } from './utils';


const methyWaldOption = {
    tooltip: {
        trigger: 'item',
        formatter: function (params: { value: string[]; }) {
            const drugNames = params.value[13];
            const maxLength = 30; // 设置最大长度
            const truncatedDrugNames = drugNames?.length > maxLength ? drugNames.substring(0, maxLength) + '...' : drugNames;

            let tooltipContent = [];

            tooltipContent.push('Gene: ' + params.value[3]);
            tooltipContent.push('TumorType: ' + params.value[4]);
            tooltipContent.push('P.Value_Single: ' + formatDecimal('', '', params.value[5]));
            tooltipContent.push('P.Value_Pancancer: ' + formatDecimal('', '', params.value[6]));
            tooltipContent.push('logFC_Single: ' + formatDecimal('', '', params.value[7]));
            tooltipContent.push('logFC_Pancancer: ' + formatDecimal('', '', params.value[8]));
    
            // 使用 join() 将内容数组转换为字符串并返回
            return tooltipContent.join('<br>');
        }
    },
    xAxis: {
        type: 'value',
        name: 'p−value (most significant tumor type)',
        nameLocation: 'middle',
        nameTextStyle: {
            padding: [5, 0, 0, 0],
            fontSize: 24,
            color: 'black',
            align: 'center',
        },
        splitLine: {
            show: false  // 隐藏 x 轴的网格线
        },
        axisLabel: {
            formatter: function (value: any) {
                // Apply inverse transformation for display

                let transformedValue = Math.pow(10, -value + 0.5)
                if (Math.abs(transformedValue) < 1e-7) {
                    return 0;
                }
                if (value === 0.5) {
                    return 1
                }
                if (transformedValue >= 0.01) {
                    return transformedValue.toFixed(2).replace(/\.?0+$/, ''); // 去除多余的小数部分
                } else if (transformedValue >= 0.001) {
                    return transformedValue.toFixed(3).replace(/\.?0+$/, ''); // 保留三位小数，并去掉无效的 0
                } else {
                    // 如果数字小于 0.001，使用科学计数法
                    return transformedValue.toExponential(1); // 科学计数法，保留一位小数
                }
            },
            customValues: [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5]
        },
        axisLine: {
            show: true,
            lineStyle: {
                color: 'black', // 设置坐标轴颜色
                width: 2 // 设置坐标轴宽度
            }
        },
        interval: 0.5
    },
    yAxis: {
        type: 'value',
        name: 'p−value (Pancancer cohort)',
        nameLocation: 'middle',
        nameTextStyle: {
            padding: [5, 0, 35, 0],
            fontSize: 24,
            color: 'black',
            align: 'center',
        },
        splitLine: {
            show: false  // 隐藏 x 轴的网格线
        },
        axisLabel: {
            formatter: function (value:any) {
              // Apply inverse transformation for display
              let transformedValue = Math.pow(10, -value + 0.5)
              if (transformedValue < 1e-4) {
                return transformedValue.toExponential(1); // 保留两位小数的科学计数法
              }
              return transformedValue > 0.00001 ? transformedValue : 0;
            },
            customValues: [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,]
        },
        axisLine: {
            show: true,
            lineStyle: {
                color: 'black', // 设置坐标轴颜色
                width: 2 // 设置坐标轴宽度
            }
        },
        min: 0,
        max: 7.5,
        interval: 0.5
    },
    legend: {
        data: ['Up', 'Down', 'No'],  // 图例名称
        orient: 'vertical',
        left: 'right',       // 放置在容器的右侧
        top: 'middle',       // 垂直居中
        align: 'left'  
    },
    color: ['#E41A1C', '#377EB8', '#BFBFBF'],
    series: [
        createScatterSeries(methyDataDownNoLabel, 'Down', 'Down', '#377EB8', 'methy', true),
        createScatterSeries(methyDataDownShowLabel, 'Down', 'Down', '#377EB8', 'methy', false), 
        createScatterSeries(methyDataUpNoLabel, 'Up', 'Up', '#E41A1C', 'methy', true),
        createScatterSeries(methyDataUpShowLabel, 'Up', 'Up', '#E41A1C', 'methy', false),
        createScatterSeries(methyDataNoNoLabel, 'No', 'No', '#BFBFBF', 'methy', true),
        createScatterSeries(methyDataNoShowLabel, 'No', 'No', '#BFBFBF', 'methy', false)
    ]
};

export default methyWaldOption